<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   design_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$_product=$this->getProduct();
$items = $_product->getRelatedProductCollection()
            ->addAttributeToSort('position', 'asc')
            ->addStoreFilter();

//echo count($items) ."#####";
?>
<?php if($this->getItems()->getSize()): ?>


  <!--        <p class="pream"><strong><?php echo $this->__('Check items to add to the cart or ') ?><a href="#" onclick="selectAllRelated(this);return false;"><?php echo $this->__('select all') ?></a></strong></p>-->
  <?php $count=1; ?>
  <?php foreach($this->getItems() as $_item): ?>
  <dl>
  <?php $_price = $this->helper('tax')->getPrice($_item, $_item->getPrice());?>
  <dt><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(170,170) ?>"/></dt>
  <?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
  <!--                <span class="checkbox-container">-->
  <?php if (!$_item->getRequiredOptions()): ?>
  <!--                    <input type="checkbox" class="related-checkbox left" id="related-checkbox<?php echo $_item->getId() ?>" 
                    name="related_products[]" value="<?php echo $_item->getId() ?>"/>-->
  <?php endif; ?>
  <!--                </span>-->
  <?php endif; ?>
  <dd>
    <div class="name"><?php echo  $this->htmlEscape($_item->getName())?><a href="<?php echo $_item->getProductUrl() ?>" style="font-size:11px; color:#000; "></a></div>
    <div class="price">Price <?php echo $this->helper('core')->currency($_price);?></div>
    <div class="option">Select Quantity & Add
      <div class="add">
        <!--<table  cellspacing="0" cellpadding="0" class="list_table">
          <tbody>
            <tr>
              <td class="number">1</td>
              <td class="button"><a href="#" class="che"><img src="<?php echo $this->getSkinUrl()?>images/che2.jpg"/></a></td>
            </tr>
          </tbody>
        </table>-->
        <div class="number"><input class="inputnumber" onchange="if(this.value.length>0)this.className='inputnumber_add'" type="text" value=""/></div><a href="#" class="che"><img src="<?php echo $this->getSkinUrl()?>images/che2.jpg"/></a>
      </div>
    </div>
  </dd>
  <?php $count++; ?>
  </dl>
  <?php endforeach ?>

<script type="text/javascript">
/*function checknum (obj){
	if(this.value.length>0 )this.className='inputnumber_add';
	checknum (obj);
}*/

//<![CDATA[
$$('.related-checkbox').each(function(elem){
    Event.observe(elem, 'click', addRelatedToProduct)
});

var relatedProductsCheckFlag = false;
function selectAllRelated(txt){
    if (relatedProductsCheckFlag == false) {
        $$('.related-checkbox').each(function(elem){
            elem.checked = true;
        });
        relatedProductsCheckFlag = true;
        txt.innerHTML="<?php echo $this->__('unselect all') ?>";
    } else {
        $$('.related-checkbox').each(function(elem){
            elem.checked = false;
        });
        relatedProductsCheckFlag = false;
        txt.innerHTML="<?php echo $this->__('select all') ?>";
    }
    addRelatedToProduct();
}

function addRelatedToProduct(){
    var checkboxes = $$('.related-checkbox');
    var values = [];
    for(var i=0;i<checkboxes.length;i++){
        if(checkboxes[i].checked) values.push(checkboxes[i].value);
    }
    if($('related-products-field')){
        $('related-products-field').value = values.join(',');
    }
}
//]]>
</script>
<?php endif ?>
